<template>
  <div>
    <q-form :model="formData">
      <q-form-item label="用户名">
        <q-input v-model="formData.username" />
      </q-form-item>
       <q-form-item label="密码">
        <q-input v-model="formData.password" type="password" />
      </q-form-item>
    </q-form>
    <q-button type="primary" @click="login">登录</q-button>
  </div>
</template>
<script>
import http from '@/http.js'
export default {
  data () {
    return {
      formData: {
        username: '',
        password: ''
      }
    }
  },
  methods: {
    login () {
      if (!this.formData.username || !this.formData.password) {
        this.$message({ type: 'warning', message: '请输入用户名密码' })
      }
      http.post('/login', this.formData)
        .then(res => {
          this.$router.push('/user')
        })
        .catch(err => {
          console.log(err.err)
        })
    }
  }
}
</script>
